<html>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/common.js"></script>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/jsmasks.js"></script>
<body>
<h1>Loading data...</h1>
<?

define("PRIMARY_KEY","nik");
$FileName       = "ais_transaction_advsummary_rpc.php";
$HTMLFormName   = "MemorialTransForm";

if (GetParam("tglbkt","") && GetParam("curr","")) {
	list($day,$month,$year) = explode("/",GetParam("tglbkt",""));
	$SQL = "SELECT rate FROM ais_kurssi WHERE tglbkt <= '$year-$month-$day' AND curr='".GetParam("curr","")."' ORDER BY tglbkt DESC LIMIT 1";
//	print $SQL;
	$rate = $DBConnection->dbc->get_var($SQL);
	if ($rate) {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = '$rate';\n";		
		$js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = oMask.format(parent.document.$HTMLFormName.rate.value);\n";
		$js_script .= "</script>\n";		
		print $js_script;		
	} else {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = '0';\n";		
		$js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
		$js_script .= "  parent.document.".$HTMLFormName.".rate.value = oMask.format(parent.document.$HTMLFormName.rate.value);\n";
		$js_script .= "</script>\n";		
		print $js_script;		
	}
} elseif (GetParam("thbl","") && GetParam("idx","")) {
	$SQL   = "SELECT skada FROM tblreceipt WHERE kdreceipt=".GetParam("thbl","");
	$skada = $DBConnection->dbc->get_var($SQL);
	if (strlen($skada)) {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.$HTMLFormName.skada".GetParam("idx","").".value = '$skada'";
		$js_script .= "</script>\n";
	} else {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.$HTMLFormName.skada".GetParam("idx","").".value = ''";
		$js_script .= "</script>\n";		
	}
	print $js_script;
} elseif (GetParam("ledger","") && GetParam("trsto","")) {
		list($day,$month,$year) = explode("/",GetParam("ledger",""));
	    $SQL   = "SELECT count(*) FROM ais_history_ledger WHERE month='$month' AND year = '$year' AND status='open'";
	    $ExistPeriod = $DBConnection->dbc->get_var($SQL);
		if (!$ExistPeriod) {
			$js_script  = "<script>\n";
			$js_script .= "  parent.document.$HTMLFormName.".GetParam("trsto","").".value = '';\n";
			$js_script .= "  alert('Invalid Date, Period Allready Closed!');\n";
			$js_script .= "  parent.document.$HTMLFormName.".GetParam("trsto","").".focus();\n";
			$js_script .= "</script>\n";
	    }
	print $js_script;	    
} elseif (GetParam("bank","")) {
	    
	    $SQL   = "SELECT coa FROM tblbank WHERE kdbank='".GetParam("bank","")."'";
	    
	    $coa = $DBConnection->dbc->get_var($SQL);
	    if ($coa) {
		    $SQL   = "SELECT currency_type FROM tblcoa WHERE skada='".$coa."'";				
	    	$curr = $DBConnection->dbc->get_var($SQL);

			$js_script  = "<script>\n";
			$js_script .= "  parent.document.$HTMLFormName.skada999.value = '$coa';\n";
			$js_script .= "  parent.setCurrency('$curr');\n";
			$js_script .= "</script>\n";		    
		}
		print $js_script;
	
} elseif (GetParam("cash","")) {
	    $SQL   = "SELECT coa FROM tblcash WHERE kdcash='".GetParam("cash","")."'";
	    $coa = $DBConnection->dbc->get_var($SQL);
	    if ($coa) {
		    $SQL   = "SELECT currency_type FROM tblcoa WHERE skada='".$coa."'";				
	    	$curr = $DBConnection->dbc->get_var($SQL);

			$js_script  = "<script>\n";
			$js_script .= "  parent.document.$HTMLFormName.skada999.value = '$coa';\n";
			$js_script .= "  parent.setCurrency('$curr');\n";
			$js_script .= "</script>\n";		    
		}
		print $js_script;
	
}


?>
